﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Admin_Login : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        // setSecureProtocol(true);
    }
    public void setSecureProtocol(bool bSecure)
    {
        string redirectUrl = null;

        // if we want HTTPS and it is currently HTTP
        if (bSecure && !Request.IsSecureConnection)
            redirectUrl = Request.Url.ToString().Replace("http:", "https:");

        else

            // if we want HTTP and it is currently HTTPS
            if (!bSecure && Request.IsSecureConnection) redirectUrl = Request.Url.ToString().Replace("https:", "http:");

        //else

        // in all other cases we don't need to redirect

        // check if we need to redirect, and if so use redirectUrl to do the job
        if (redirectUrl != null)

            Response.Redirect(redirectUrl);

    }
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        if (Membership.ValidateUser(Login1.UserName, Login1.Password))
        {


            if (Roles.IsUserInRole(Login1.UserName, "Admin"))
            {
                e.Authenticated = true;
                Login1.Visible = false;
             Login1.DestinationPageUrl="~/Admin/default.aspx";
            }
            else
            {
                Login1.FailureText = "You are not authorizied for admin login.";
                e.Authenticated = false;
            }
        }
        else
        {
            e.Authenticated = false;
        }
    }
}
